﻿var Marquee=function(marqueeDiv,contentDiv,contents){
 this.marqueeDiv=marqueeDiv;
 if (contents!=null){
 this.marqueeContents=contents;
 }else{
 this.marqueeContents=new Array();
 var lis=document.getElementById(contentDiv).getElementsByTagName('LI');
 for (var i=0;i<lis.length;i++){
 this.marqueeContents[i]=lis[i].innerHTML;
 }
 }
 this.marqueeInterval=new Array();
 this.marqueeId=0;
 this.marqueeDelay=2000;
 this.marqueeHeight=23;
};

Marquee.prototype={
 createMarquee:function(mdiv,oname,w){
 var len=this.marqueeContents.length;
 if (len==0){
 return;
 }
 if (w==null){
 w=280;
 }
 var str='<div id='+this.marqueeDiv+' style="overflow:hidden;float:left;width:'+w+'px;height:'+this.marqueeHeight+'px" onmouseover="clearInterval('+oname+'.marqueeInterval[0])" onmouseout="'+oname+'.marqueeInterval[0]=setInterval(\''+oname+'.startMarquee(\\\''+oname+'\\\')\','+oname+'.marqueeDelay)"><div>'+this.marqueeContents[0]+'</div></div>';
 var elm=document.createElement('span');
 elm.innerHTML=str;
 document.getElementById(mdiv).appendChild(elm);
 if (len==1){
 return;
 }
 this.initMarquee(oname);
 },

 initMarquee:function(oname){
 this.marqueeId++;
 this.marqueeInterval[0]=setInterval(oname+".startMarquee('"+oname+"')",this.marqueeDelay);
 },

 startMarquee:function(oname){
 if (this.marqueeContents.length<2){
 return;
 }
 var str=this.marqueeContents[this.marqueeId];
 this.marqueeId++;
 if(this.marqueeId>=this.marqueeContents.length) this.marqueeId=0;
 if(document.getElementById(this.marqueeDiv).childNodes.length==1) {
 var nextLine=document.createElement('DIV');
 nextLine.innerHTML=str;
 document.getElementById(this.marqueeDiv).appendChild(nextLine);
 }else{
 document.getElementById(this.marqueeDiv).childNodes[0].innerHTML=str;
 document.getElementById(this.marqueeDiv).appendChild(document.getElementById(this.marqueeDiv).childNodes[0]);
 document.getElementById(this.marqueeDiv).scrollTop=0;
 }
 clearInterval(this.marqueeInterval[1]);
 this.marqueeInterval[1]=setInterval(oname+".scrollMarquee()",20);
 },

 scrollMarquee:function(){
 document.getElementById(this.marqueeDiv).scrollTop++;
 if(document.getElementById(this.marqueeDiv).scrollTop%this.marqueeHeight==(this.marqueeHeight-1)){
 clearInterval(this.marqueeInterval[1]);
 }
 }
};